home *** CD-ROM | disk | FTP | other *** search
/ Czech Logic, Card & Gambling Games / Logické hry.iso / hry / Robocode / robocode-setup-1.0.7.jar / extract.jar / robots / sample / MyFirstRobot.java < prev    next >
Encoding:
Java Source  |  2005-02-18  |  802 b   |  37 lines

  1. package sample;
  2. import robocode.*;
  3. /**
  4.  * MyFirstRobot - a sample robot by Mathew Nelson
  5.  * 
  6.  * Moves in a seesaw motion, and spins the gun around at each end
  7.  */
  8. public class MyFirstRobot extends Robot
  9. {
  10.     /**
  11.      * MyFirstRobot's run method - Seesaw
  12.      */
  13.     public void run() {
  14.         
  15.         while (true) {
  16.             ahead(100);            // Move ahead 100
  17.             turnGunRight(360);    // Spin gun around    
  18.             back(100);            // Move back 100
  19.             turnGunRight(360);    // Spin gun around
  20.         }
  21.     }
  22.     
  23.     /**
  24.      * Fire when we see a robot
  25.      */
  26.     public void onScannedRobot(ScannedRobotEvent e) {
  27.         fire(1);
  28.     }
  29.     
  30.     /**
  31.      * We were hit!  Turn perpendicular to the bullet,
  32.      * so our seesaw might avoid a future shot.
  33.      */
  34.     public void onHitByBullet(HitByBulletEvent e) {
  35.         turnLeft(90 - e.getBearing());
  36.     }
  37. }